import { View, Image, Text } from '@tarojs/components'
import QRCode from 'react-qr-code';
import { useState, useEffect, useRef } from 'react'
import LgButton from '@/pages/components/button'
import LgCell from '@/pages/components/cell'
import Header from '@/pages/components/navCustomBar'
import { LgPopLayer } from '@/pages/components/popLayer'
import Taro from '@tarojs/taro'
import { HttpGet, HttpDelete, HttpPost } from '@/network/servers'
import dayjs from 'dayjs'
import Utils from '@/utils/index'
import { connect } from 'react-redux'
import { AtSegmentedControl } from 'taro-ui'
import Loading from '../component/load'
import Proxy from '@/network/proxy'
import { requestSystemUrl } from '@/network/baseUrl'
import LgSearch from "@/pages/components/search";
// import { LgSearch } from "lancoo-ui-mobile";
import { getBrowserController, getNet, getStorage, getWxSDKParams } from '@/pages/components/utils';
import '../../images/public/style.css'
import './index.scss'
const browserController = getBrowserController()
const net = getNet()
const storage = getStorage()
var wx = require('weixin-js-sdk')
const {
  getNowEnvironment,
  getNowToken,
  RemoveHTML,
  getQueryVariable,
  getDateGap,
  getDate,
  getDate1,
  replaceHost
} = Utils


const requireContext = require.context("../../images/fileIcon", true, /^\.\/.*\.svg$/);
const svgs = requireContext.keys().map(requireContext);
const keys = requireContext.keys()
let fileObj = {}

keys.map((item, index) => {
  let str = item.replace('./', "").replace('.svg', "")
  fileObj[str] = svgs[index]
})


function App(props) {

  let {
    noticeAddr,
    userInfo,
    env,
    baseUrl,
    basicsAddr
  } = props



  const getToken = () => {
    if (getQueryVariable('env') === 'weapp') {
      return getQueryVariable('lg_tk')
    } else {
      return storage.get('token') || getQueryVariable('lg_tk')
    }
  }

  const [init, setInit] = useState(false)
  const [detail, setDetail] = useState(null);//详情信息
  const [user, setUser] = useState(null);//详情信息
  const [mainServerAddr, setMainServerAddr] = useState('');//详情信息
  const [scheduleId, setScheduleId] = useState('');
  const [height, setHeight] = useState(0);
  const [week, setWeek] = useState(0);//周几
  const [month, setMonth] = useState(0);//月份
  const [day, setDay] = useState(0);//日期
  const [mainScheduleId, setMainScheduleId] = useState('');//重复日程主进程ID
  const [scheduleDay, setScheduleDay] = useState('');//日程时间
  const [participantList, setParticipantList] = useState([]);//参与人列表
  const [accept, setAccept] = useState([]);//参与人接受列表
  const [refuse, setRefuse] = useState([]);//参与人拒绝列表
  const [confirmed, setConfirmed] = useState([]);//参与人待定列表
  const [unread, setUnread] = useState([]);//参与人未读列表
  const [visible, setVisible] = useState(false);//参与人弹出层
  const [current, setCurrent] = useState(0);//参与人状态Tab切换
  const [signInVoList, setSignInVoList] = useState([]);//会议签到
  const [signInVoSearchList, setSignInVoSearchList] = useState([]);//会议签到搜索列表
  const [search, setSearch] = useState(false);//会议签到搜索列表
  const [signList, setSignList] = useState([]);//已签到列表
  const [noSignList, setNoSignList] = useState([]);//未签到列表
  const [visible1, setVisible1] = useState(false);//签到人弹出层
  const [isQRcodePopOpen, setIsQRcodePopOpen] = useState(false);//二维码
  const [duration, setDuration] = useState<any>(0);//日程时长
  const [startTime, setStartTime] = useState('');//开始时间
  const [endTime, setEndTime] = useState('');//结束时间
  const [qrCodeUrl, setQrCodeUrl] = useState('');  // 用来存储二维码的Data URL
  const canvasRef = useRef(null); // 使用ref来引用canvas元素
  const svgRef = useRef(null);
  const weeks = {
    1: '周一',
    2: '周二',
    3: '周三',
    4: '周四',
    5: '周五',
    6: '周六',
    7: '周日',
  };

  const getCommonData = () => {
    if (Utils.getQueryVariable('env') === 'weapp' || window.__wxjs_environment === 'miniprogram') {
      // 小程序端的h5
      if (!baseUrl) {

        //应用外跳转
        let instance = Taro.getCurrentInstance()

        const browserController = getBrowserController()
        let height = browserController.getStatusBarHeight()
        setHeight(height)
        if (instance.router?.params) {
          let params = instance.router.params
          let id = params.id
          let eduId = params.eduId
          // console.log(params);

          setScheduleId(id)
          // console.log(scheduleId, 'scheduleId', getQueryVariable('lg_tk'), '123', params);

          if (JSON.stringify(userInfo) === '{}') {
            // goHome();
            Taro.getSysWeb({ sysId: '260', eduId }, 'web', function (res) {
              let MainServerAddr = res
              setMainServerAddr(MainServerAddr);
              HttpGet({   //用户信息
                url: MainServerAddr + '/api/common/user',
                data: {
                  token: Utils.getQueryVariable('lg_tk')
                }
              }).then((res1) => {
                let user = res1.data;
                setUser(user);
                setTimeout(() => {
                  doCommonLogic(id, user, MainServerAddr)
                }, 300);
              })
            })
            // return;
          } else {
            doCommonLogic(id, null, '')
          }
        }
      } else {

        //应用内跳转
        let instance = Taro.getCurrentInstance()

        const browserController = getBrowserController()
        let height = browserController.getStatusBarHeight()
        setHeight(height)
        if (instance.router?.params) {
          let params = instance.router.params
          let id = params.id
          let eduId = params.eduId
          // console.log(params);

          setScheduleId(id)
          // console.log(scheduleId, 'scheduleId', getQueryVariable('lg_tk'), '123', params);

          if (JSON.stringify(userInfo) === '{}') {
            // goHome();
            Taro.getSysWeb({ sysId: '260', eduId }, 'web', function (res) {
              let MainServerAddr = res
              setMainServerAddr(MainServerAddr);
              HttpGet({   //用户信息
                url: MainServerAddr + '/api/common/user',
                data: {
                  token: Utils.getQueryVariable('lg_tk')
                }
              }).then((res1) => {
                let user = res1.data;
                setUser(user);
                setTimeout(() => {
                  doCommonLogic(id, user, MainServerAddr)
                }, 300);
              })
            })
            // return;
          } else {
            doCommonLogic(id, null, '')
          }
        }
      }
    } else {
      // app内 1.应用内跳转(不需要获取通知地址和用户信息) 2.直接跳转
      let instance = Taro.getCurrentInstance()

      const browserController = getBrowserController()
      let height = browserController.getStatusBarHeight()
      setHeight(height)
      if (instance.router?.params) {
        let params = instance.router.params
        let id = params.id
        let eduId = params.eduId

        console.log(params, 'params',);

        setScheduleId(id)
        // console.log(scheduleId, 'scheduleId', getQueryVariable('lg_tk'), '123', params);

        if (JSON.stringify(userInfo) === '{}') {
          // goHome();
          Taro.getSysWeb({ sysId: '260', eduId }, 'web', function (res) {
            let MainServerAddr = res
            setMainServerAddr(MainServerAddr);
            HttpGet({   //用户信息
              url: MainServerAddr + '/api/common/user',
              data: {
                token: Utils.getQueryVariable('lg_tk')
              }
            }).then((res1) => {
              let user = res1.data;
              setUser(user);
              setTimeout(() => {
                doCommonLogic(id, user, '')
              }, 300);
            })
          })
          // return;
        } else {
          doCommonLogic(id, null, '')
        }
      }
    }
  }

  function doCommonLogic(id, user, MainServerAddr) {
    let url = "/api/schedule/info/detail"
    if (MainServerAddr != '') {
      url = MainServerAddr + url;
    }

    HttpGet({
      url,
      data: {
        scheduleId: id,
        eduId: userInfo.eduId || user?.eduId,
        userType: userInfo.userType || user?.userType,
      }
    }).then(res => {
      if (res.code == 200 && res.data) {
        setDetail(res.data);
        let startDate = res.data.scheduleDate + ' ' + res.data.startTime;
        let endDate = res.data.scheduleDate + ' ' + res.data.endTime;
        let durationTime = getDateGap(startDate, endDate);
        // let durationTime = dayjs(endDate).diff(startDate,'h');
        // console.log(durationTime,'durationTime');
        let week = dayjs(startDate).day();
        let month = dayjs(startDate).month();
        let day = dayjs(startDate).date();
        setStartTime(startDate);
        setEndTime(endDate);
        setScheduleDay(res.data.scheduleDate);
        setWeek(week);
        setMonth(month + 1);
        setDay(day);
        setDuration(durationTime);
        //遍历参与人列表
        if (userInfo.userType !== '2' || user?.userType !== '2') {
          let participant = res.data?.scheduleMemberVoList || [];
          setParticipantList(participant);
          let acceptList = [];
          let refuseList = [];
          let confirmedList = [];
          let unreadList = [];
          if (participant.length > 0) {
            participant.map(item => {
              if (item.attendFlag == '0') {
                unreadList.push(item);
              } else if (item.attendFlag == '1') {
                confirmedList.push(item);
              } else if (item.attendFlag == '2') {
                acceptList.push(item);
              } else if (item.attendFlag == '3') {
                refuseList.push(item);
              }
            })
            if (acceptList.length == 0) {
              if (refuseList.length > 0) {
                setCurrent(1);
              } else if (confirmedList.length > 0) {
                setCurrent(2);
              } else {
                setCurrent(3);
              }
            }
            setAccept(acceptList);
            setRefuse(refuseList);
            setConfirmed(confirmedList);
            setUnread(unreadList);
          }
          let signInVoLis = res.data?.scheduleMemberSignInVoList || [];
          let signList1 = [], noSignList1 = [];
          setSignInVoList(signInVoLis);
          if (signInVoLis.length > 0) {
            // console.log(signInVoLis, 'signInVoLis');
            signInVoLis.map(item => {
              if (item.signInStatus == '0') {
                noSignList1.push(item);
              } else if (item.signInStatus == '1') {
                signList1.push(item);
              }
            })
          }
          setSignList(signList1);
          setNoSignList(noSignList1)
        }
        setInit(true);
      } else {
        Taro.showToast({
          title: res.msg,
          icon: 'none',
          duration: 2000
        })
      }
    })
  }

  const goBack = () => {
    console.log(isQRcodePopOpen, 'isQRcodePopOpen');
    if (isQRcodePopOpen) {
      console.log(isQRcodePopOpen, 'isQRcodePopOpen');
      setIsQRcodePopOpen(false);
      setQrCodeUrl('');
    } else {
      Taro.navigateBack({
        delta: 1
      })
      // Taro.redirectTo({
      //   url: '/pages/scheduleApp/index'
      // })
    }
  }

  const initWxSdk = async () => {
    const params = getWxSDKParams(['previewImage', 'getLocation'])
    wx.config(params);
    wx.ready(function () {
      // config信息验证后会执行 ready 方法，所有接口调用都必须在 config 接口获得结果之后，config是一个客户端的异步操作，所以如果需要在页面加载时就调用相关接口，则须把相关接口放在 ready 函数中调用来确保正确执行。对于用户触发时才调用的接口，则可以直接调用，不需要放在 ready 函数中。
      console.log('ready')
    });
    wx.error(function (res) {
      // config信息验证失败会执行 error 函数，如签名过期导致验证失败，具体错误信息可以打开 config 的debug模式查看，也可以在返回的 res 参数中查看，对于 SPA 可以在这里更新签名。
      console.log(res)
    });
  }

  useEffect(() => {
    document.title = '日程详情'
    if (window.__wxjs_environment === 'miniprogram') {
      initWxSdk()
    }
    getCommonData()
    return () => {
      if (Utils.getSystemInfo() === 'weapp') {
        document.title = '日程详情'
        window.getScheduleList && typeof window.getScheduleList === 'function' && window.getScheduleList()
      }
    }
  }, []);

  useEffect(() => {
    if (JSON.stringify(userInfo) === '{}') {
      // goHome();
    }
  }, [userInfo])

  //返回首页
  const goHome = () => {
    Taro.navigateTo({
      url: '/pages/scheduleApp/index?id='
    });
  }

  //打开参会人弹出层
  const handlePopLayer = (type, full = "") => {
    if (type === 'open') {
      setVisible(true);
    } else {
      setVisible(false);
    }
  }

  //tab选项
  const handleClick = (value) => {
    setCurrent(value);
  }
  //打开签到人弹出层
  const handlePopLayer1 = (type, full = "") => {
    if (type === 'open') {
      setVisible1(true);
    } else {
      setVisible1(false);
    }
  }
  //来源，编辑，删除操作
  const operation = (type) => {

    switch (type) {
      case 'source': console.log(type, 'type');
        break;
      case 'edit':
        let url = '/pages/scheduleApp/createSchedule/index?id=' + scheduleId
        Taro.navigateTo({
          url
        });
        break;
      case 'del':
        Taro.showModal({
          title: '提示',
          content: '是否删除日程？',
          success: function (res) {
            let url = '/api/schedule/manage/delete?id='
            if (mainServerAddr != '') {
              url = mainServerAddr + url;
            }
            if (res.confirm) {
              HttpDelete({
                url,
                data: {
                  scheduleId: scheduleId,
                  mainScheduleId: mainScheduleId,
                  userType: userInfo.userType || user?.userType,
                  eduId: userInfo.eduId || user?.eduId,
                  originalScheduleDate: scheduleDay,
                  scheduleMemberBoListOld: participantList,
                }
              }).then((result) => {
                if (result.code === '200') {
                  Taro.showToast({
                    title: '删除成功',
                    duration: 2000,
                    mask: true
                  })
                  setTimeout(() => {
                    goHome();
                  }, 2000);
                }
              })
            } else if (res.cancel) {
              // console.log('用户点击取消')
            }
          }
        })

        break;
    }

  }
  const searchPerson = (per) => {
    // 使用 filter 方法遍历数组，返回符合条件的项
    const filteredList = signInVoList.filter(item => {
      // 这里假设 per 是一个字符串，你可以根据 per 来判断每一项是否包含该字符串
      // 可以根据实际需要修改条件，例如检查某个字段是否包含 per
      return Object.values(item).some(value => value.toString().includes(per));
    });
    if (per == '') {
      setSignInVoSearchList([]);
      setSearch(false);
    } else {
      setSignInVoSearchList(filteredList);
      setSearch(true);
    }
  }

  const checkIfEnded = (endTime) => {
    // 获取当前时间
    const currentTime = dayjs();

    // 将传入的结束时间转换为 dayjs 对象
    const endTimeObj = dayjs(endTime);

    // 判断结束时间是否已过
    if (endTimeObj.isBefore(currentTime)) {
      // 已结束
      return true;
    } else {
      // 未结束
      return false;
    }
  };
  const changeSign = (item, idx, type) => {
    let url = 'api/schedule/member/updateSignInStatus'
    let data = {
      scheduleId: item?.scheduleId,
      eduId: item?.eduId,
      userId: item?.userId,
      signInStatus: item?.signInStatus == '1' ? 0 : 1,
    }
    let resultTime = checkIfEnded(endTime);
    if (resultTime) {
      Taro.showToast({
        title: '会议已结束！',
        icon: 'error',
        duration: 3000,
      })
      return;
    }
    HttpPost({
      url,
      data: data
    }).then((res) => {
      if (res.code == 200) {
        Taro.showToast({
          icon: 'success',
          duration: 3000,
          title: '设置成功'
        })
        if (type == 'search') {
          let updatedList: any = [...signInVoSearchList];  // 创建列表的副本，防止直接修改
          updatedList[idx] = {
            ...updatedList[idx],
            signInStatus: data.signInStatus,  // 更新 signInStatus
          };
          setSignInVoSearchList(updatedList);  // 更新状态
          let index = signInVoList.findIndex(itm => itm.userId == item?.userId);
          let updatedList2: any = [...signInVoList];  // 创建列表的副本，防止直接修改
          updatedList2[index] = {
            ...updatedList2[index],
            signInStatus: data.signInStatus,  // 更新 signInStatus
          };
          setSignInVoList(updatedList2);  // 更新状态
        } else {
          let updatedList1: any = [...signInVoList];  // 创建列表的副本，防止直接修改
          updatedList1[idx] = {
            ...updatedList1[idx],
            signInStatus: data.signInStatus,  // 更新 signInStatus
          };
          setSignInVoList(updatedList1);  // 更新状态
        }
      } else {
        Taro.showToast({
          title: res.msg,
          icon: 'error',
          duration: 3000,
        })
      }
    })
      .catch((error) => {
        // 错误处理逻辑
        console.error('请求失败:', error);
        Taro.showToast({
          icon: 'none',
          duration: 3000,
          title: error.msg,
        });
      });
  }

  const openQr = () => {
    let url = baseUrl + 'scheduleSignIn/h5/index.html?scheduleId=' + scheduleId
    // generateQRCode(url);
    setQrCodeUrl(url)
    setIsQRcodePopOpen(true);
  }

  // 保存二维码图片的函数
  const saveQRCode = async () => {
    Taro.showToast({
      title: '请自行截图保存~',
      duration: 3000,
      icon: 'none',
    })
    return

    const imageUrl = detail?.qrCodePage || '';
    if (imageUrl == '') {
      Taro.showToast({
        title: '请自行截图保存~',
        duration: 3000,
        icon: 'none',
      })
      return
    }

    try {
      // 通过 fetch 获取图片数据（处理跨域）
      const response = await fetch(imageUrl);
      const blob = await response.blob();

      // 创建 Blob URL 并下载
      const url = window.URL.createObjectURL(blob);
      const link = document.createElement('a');
      link.href = url;
      link.download = (detail?.scheduleTitle + '.jpg') || 'qrcode.jpg';
      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link);
      window.URL.revokeObjectURL(url);
    } catch (error) {
      Taro.showToast({ title: '下载失败', icon: 'none' });
    }
  };
  const shareFile = () => {//分享文件
    let fileItem = qrCodeUrl
    if (!fileItem) return
    let data = `文件名：${detail?.scheduleTitle},\n下载地址：${fileItem}`
    console.log(data, 'data');

    Taro.setClipboardData({
      data: data,
      success: function (res) {
        Taro.showToast({
          title: "已复制下载链接到粘贴板",
          icon: "none",
          duration: 2000
        })
      }
    })
  }
  // 通过canvas方式渲染QRCode
  // useEffect(() => {
  //   // 在 useEffect 中处理组件挂载的情况
  //   let isMounted = true; // 标记组件是否已挂载
  //   console.log(qrCodeUrl, 'qrCodeUrl', canvasRef.current, 'canvasRef.current', isMounted);

  //   if (qrCodeUrl && canvasRef.current && isMounted) {
  //     const canvas = canvasRef.current;
  //     const context = canvas.getContext('2d');
  //     console.log(qrCodeUrl, 'qrCodeUrl');

  //     // 使用 `react-qr-code` 生成二维码
  //     const img = new Image();
  //     img.src = QRCode.toDataURL(qrCodeUrl); // 获取二维码的图片URL
  //     img.onload = () => {
  //       if (isMounted && context) {
  //         context.drawImage(img, 0, 0); // 在 canvas 上绘制二维码
  //       }
  //     };
  //   }



  //   // 组件卸载时清理
  //   return () => {
  //     isMounted = false;
  //   };
  // }, [qrCodeUrl]); // 仅在 qrCodeUrl 改变时运行

  // 封装生成二维码的方法
  // const generateQRCode = (url) => {
  //   QRCode.toDataURL(url, (error, dataUrl) => {
  //     if (error) {
  //       console.error("Error generating QR code", error);
  //     } else {
  //       setQrCodeUrl(dataUrl);  // 将生成的二维码Data URL设置到state中
  //     }
  //   });
  // };
  if (!init) {
    return (
      <View>
        <Loading content='加载中' isOpened={true} />
      </View>
    )
  }
  let nowDay = dayjs().format('YYYY-MM-DD HH:mm');
  console.log(detail.beAllDay, 'detail.beAllDay')
  const signCount = signInVoList.filter(item => item?.signInStatus == 1).length || 0;
  const noSignCount = signInVoList.filter(item => item?.signInStatus == 0).length || 0;
  return (
    <View className="scheduleDetail">
      {
        Utils.getQueryVariable('env') === 'weapp' || window.__wxjs_environment === 'miniprogram' ?
          "" :
          <Header
            className='header-top'
            mainTitle={isQRcodePopOpen ? '签到二维码' : '日程详情'}
            mainTitleBlod={false}
            isTitlePositionLeft={true}
            needMainIcon={process.env.TARO_ENV === 'weapp' ? false : true}
            onClick={Utils.getSystemInfo() !== 'weapp' ? goBack : ''}
          />
      }
      {
        isQRcodePopOpen ?
          <View className={Utils.getSystemInfo() === 'weapp' ? 'qr_view qr_view_weapp' : 'qr_view'} onClick={() => goBack()}>
            <View className='qr_img_view' onClick={(e) => e.stopPropagation()}>
              <View className='qr_title'>{detail?.scheduleTitle}</View>
              <View className='qr_time_address'>
                <View className='qr_time'>{dayjs(startTime).format('YYYY/MM/DD HH:mm') + '-' + dayjs(endTime).format('YYYY/MM/DD HH:mm')}</View>
                <View className='qr_address'><Text className='qr_address_text'>{detail?.scheduleLocation}</Text><Text >{detail?.userName}</Text></View>
              </View>
              <View className='qr_img'>
                {/* {qrCodeUrl && <canvas ref={canvasRef} width="200" height="200" />} */}
                <QRCode
                  // value={qrCodeUrl}
                  value={detail?.qrCode ? detail?.qrCode : qrCodeUrl}
                  size={180}
                  renderAs="svg"
                // ref={svgRef}
                />

                {/* Canvas元素用于保存图片 */}
                {/* <canvas ref={canvasRef} width="180" height="180" style={{ display: 'none' }} /> */}
                {/* {qrCodeUrl && <QRCode value={qrCodeUrl} className="QRImage" ref={canvasRef} />} */}
              </View>
              <View className='qr_tip'>请使用微信或浏览器扫码签到</View>
            </View>
            <View className='qr_btn_view' onClick={(e) => e.stopPropagation()}>
              <LgButton type='D' border='white' className='save_btn' onClick={() => saveQRCode()}>保存到本地</LgButton>
              <LgButton type='D' border='white' className='share_btn' onClick={() => shareFile()}>分享</LgButton>
            </View>
          </View>
          :
          <View>
            {
              detail ?
                <View className='schedule-container'>
                  <View className='header'>
                    <View className='title'>{detail.scheduleTitle}</View>
                    <View className='line'></View>
                    <View className='time-info'>
                      <View className='time-info-left'>
                        <Text className='days'>{month}月{day}日 {weeks[week]}</Text>
                        <Text className='times'>{detail.startTime}</Text>
                      </View>
                      <View className='duration'>
                        <Text style={{ margin: '0 0 0 10px', color: 'rgb(238, 241, 243)' }}>—</Text>
                        <View className='duration-time'>
                          <Text >{detail.beAllDay == '1' ? '24' : duration}小时</Text>
                        </View>
                        <Text style={{ margin: '0 10px 0 0', color: 'rgb(238, 241, 243)' }}>—</Text>
                      </View>
                      <View className='time-info-right'>
                        <Text className='days'>{month}月{day}日 {weeks[week]}</Text>
                        <Text className='times'>{detail.endTime}</Text>
                      </View>
                    </View>
                  </View>
                  <View className='place-detail'>
                    <View className='place'>地点<View className='address '>{detail.scheduleLocation ? detail.scheduleLocation : '--'}</View></View>
                    <View className='line line-long'></View>
                    <View className='detail'>日程描述<View className='describe'>{detail.scheduleContent ? detail.scheduleContent : '--'}</View></View>
                  </View>
                  {(userInfo.userType !== '2' || user?.userType !== '2') && participantList.length > 0 ?
                    <View className='participant'>
                      <LgCell
                        title="参与人"
                        content={<View className='participant-details'><Text className='confirm-people'>{accept.length}</Text>人已确认，<Text className='cancel-people'>{refuse.length}</Text>人已拒绝，
                          <Text className='undetermined-people'>{confirmed.length}</Text>人待定，{unread.length}人未读</View>}
                        showIcon={true}
                        onClick={() => {
                          handlePopLayer('open')
                        }}
                        type='A'
                      ></LgCell>

                      <LgPopLayer
                        position="bottom"
                        confirm={() => { handlePopLayer('close') }}
                        showLayer={() => handlePopLayer('close')}
                        title={'参与人详情'}
                        showClose
                        isOpen={visible}
                      >
                        <View className='tabs_container'>
                          <AtSegmentedControl
                            values={[`已接受(${accept.length})`, `已拒绝(${refuse.length})`, `待定(${confirmed.length})`, `未读(${unread.length})`]}
                            onClick={handleClick.bind(this)}
                            current={current}
                            selectedColor='rgb(0,153,255)'
                            color='rgb(255,255,255)' />
                          {current === 0
                            ?
                            <View className='tab-content'>
                              {
                                accept.map(item => {
                                  if (Utils.getQueryVariable('env') === 'weapp' || window.__wxjs_environment === 'miniprogram') {
                                    item.photoPath = replaceHost(item.photoPath, basicsAddr)
                                  }
                                  return (
                                    <View className='user-info'>
                                      <View className='user-photo' style={{ backgroundImage: `url(${item.photoPath})` }}></View>
                                      <View className='user-name'>{item.userName}</View>
                                      <View className='user-id'>{item.userId}</View>
                                    </View>
                                  )
                                })
                              }
                            </View>
                            : null}
                          {current === 1
                            ?
                            <View className='tab-content'>
                              {refuse.map(item => {
                                if (Utils.getQueryVariable('env') === 'weapp' || window.__wxjs_environment === 'miniprogram') {
                                  item.photoPath = replaceHost(item.photoPath, basicsAddr)
                                }
                                return (
                                  <View className='user-info'>
                                    <View className='user-photo' style={{ backgroundImage: `url(${item.photoPath})` }}></View>
                                    <View className='user-name'>{item.userName}</View>
                                    <View className='user-id'>{item.userId}</View>
                                  </View>
                                )
                              })}
                            </View>
                            : null}
                          {current === 2
                            ? <View className='tab-content'>  {
                              confirmed.map(item => {
                                if (Utils.getQueryVariable('env') === 'weapp' || window.__wxjs_environment === 'miniprogram') {
                                  item.photoPath = replaceHost(item.photoPath, basicsAddr)
                                }
                                return (
                                  <View className='user-info'>
                                    <View className='user-photo' style={{ backgroundImage: `url(${item.photoPath})` }}></View>
                                    <View className='user-name'>{item.userName}</View>
                                    <View className='user-id'>{item.userId}</View>
                                  </View>
                                )
                              })
                            }</View>
                            : null}
                          {current === 3
                            ? <View className='tab-content'>  {
                              unread.map(item => {
                                if (Utils.getQueryVariable('env') === 'weapp' || window.__wxjs_environment === 'miniprogram') {
                                  item.photoPath = replaceHost(item.photoPath, basicsAddr)
                                }
                                return (
                                  <View className='user-info'>
                                    <View className='user-photo' style={{ backgroundImage: `url(${item.photoPath})` }}></View>
                                    <View className='user-name'>{item.userName}</View>
                                    <View className='user-id'>{item.userId}</View>
                                  </View>
                                )
                              })
                            }</View>
                            : null}
                        </View>
                      </LgPopLayer>
                    </View> : ''}
                  {signInVoList.length > 0 ?
                    <View className='signIn_VoLis'>
                      <LgCell
                        className='sign_cell'
                        title="会议签到"
                        content={<View className='signIn-details'><Text className='signIn-people'>{signCount}</Text>人已签到，
                          <Text className='no-signIn-people'>{noSignCount}</Text>人未签到
                        </View>}
                        showIcon={true}
                        onClick={() => {
                          handlePopLayer1('open')
                        }}
                        type='A'
                      ></LgCell>

                      <LgPopLayer
                        position="bottom"
                        confirm={() => { handlePopLayer1('close') }}
                        showLayer={() => handlePopLayer1('close')}
                        title={'签到详情'}
                        showClose
                        isOpen={visible1}
                      >
                        <View className='sign_container'>
                          <View className='search_view'>
                            <LgSearch placeholder="搜索人名/工号" onInput={(value) => searchPerson(value)}></LgSearch>
                          </View>
                          <View className='sign_person_view'>
                            {
                              search ?
                                signInVoSearchList.map((item, index) => {
                                  return (
                                    <View className='sign_person_item'>
                                      <View className='sign_index'> {index + 1}</View>
                                      <View className='sign_info'>
                                        <View className='person_info'>
                                          <View className={'person_photo ' + (index > 8 ? 'person_photo1' : '')} style={{ backgroundImage: `url(${item?.photoPath + '&lg_tk=' + getToken()})` }}></View>
                                          <View className='person_name'><Text className='person_name_text'>{item?.userName}</Text><Text className='person_id'>（{item?.userId}）</Text></View>
                                          <View className={'person_sign_status ' + (item?.signInStatus == 1 ? 'sign_status' : '')}>{item?.signInStatus == 1 ? '已' : '未'}签到</View>
                                        </View>
                                      </View>
                                      <View className='sign_btn'>
                                        <Text className='sign_text' onClick={() => changeSign(item, index, 'search')}>设为{item?.signInStatus == 1 ? '未' : '已'}签到</Text>
                                      </View>
                                    </View>
                                  )
                                })
                                :
                                signInVoList.map((item, index) => {
                                  return (
                                    <View className='sign_person_item'>
                                      <View className='sign_index'> {index + 1}</View>
                                      <View className='sign_info'>
                                        <View className='person_info'>
                                          <View className={'person_photo ' + (index > 8 ? 'person_photo1' : '')} style={{ backgroundImage: `url(${item?.photoPath + '&lg_tk=' + getToken()})` }}></View>
                                          <View className='person_name'><Text className='person_name_text'>{item?.userName}</Text><Text className='person_id'>（{item?.userId}）</Text></View>
                                          <View className={'person_sign_status ' + (item?.signInStatus == 1 ? 'sign_status' : '')}>{item?.signInStatus == 1 ? '已' : '未'}签到</View>
                                        </View>
                                      </View>
                                      <View className='sign_btn'>
                                        <Text className='sign_text' onClick={() => changeSign(item, index, 'noSearch')}>设为{item?.signInStatus == 1 ? '未' : '已'}签到</Text>
                                      </View>
                                    </View>
                                  )
                                })
                            }
                          </View>
                        </View>
                      </LgPopLayer>
                    </View> : ''}
                  {
                    detail?.beSignIn == '1' ?
                      <View className='qr_code_view'>
                        <Text className='qr_btn' onClick={() => openQr()}>签到二维码</Text>
                      </View>
                      : ''
                  }
                </View> : null
            }
            {
              Utils.getQueryVariable('isFromOther') == '1' ?
                '' :
                <View className="index-footer">
                  {/* <LgButton className="send-btn source-btn" type='D' onClick={() => operation('source')} > 来源</LgButton> */}
                  {
                    nowDay <= startTime || detail.beAllDay == '1' ?
                      <LgButton className="send-btn edit-btn" type='D' onClick={() => operation('edit')} > 编辑</LgButton>
                      : ''
                  }
                  <LgButton className="send-btn delete-btn" color='close' type='D' onClick={() => operation('del')} >删除</LgButton>
                </View>
            }
          </View>
      }
    </View>
  )
}

const mainProps = ({ commonData }) => {
  console.log(commonData, 'commonData');

  return {
    userInfo: commonData.userInfo,
    env: commonData.env,
    noticeAddr: commonData.noticeAddr,
    baseUrl: commonData.baseUrl,
    basicsAddr: commonData.basicsAddr,
  }
}

export default connect(mainProps)(App);
